﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MediatR;
using SystemHYS.API.Application.command.GualityGroupCommand;
using SystemHYS.API.DTOS;
using SystemHYS.API.Application.command.GualitySchemeCommmand;
using SystemHYS.Domian.DTO;
using SystemHYS.Domian;
using SystemHYS.API.Application.command.GualityProjectCommand;
using Microsoft.AspNetCore.Authorization;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database;

namespace SystemHYS.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [Authorize]
    [ApiController]
    public class GualitySchemeController : ControllerBase
    {
        IMediator mediator;
        public GualitySchemeController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加质检方案信息
        /// </summary>
        /// <param name="command">质检方案信息</param>
        /// <returns>返回受影响信息</returns>
        [HttpPost]
        public async Task<Apiresult<int>> AddGualityScheme(GualitySchemeCreateCommmand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 获取质检方案信息
        /// </summary>
        /// <param name="command">查询</param>
        /// <returns>返回质检方案集合</returns>
        [HttpGet]
        public async Task<Apiresult<PageDTO<GualityScheme>>> GetGualityScheme([FromQuery]GualitySchemeShowCommmand command)
        {
            Apiresult<PageDTO<GualityScheme>> apiresult = new Apiresult<PageDTO<GualityScheme>>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 删除质检方案信息
        /// </summary>
        /// <param name="command">质检方案Id</param>
        /// <returns>返回受影响信息</returns>
        [HttpPost]
        public async Task<Apiresult<int>> DeleteGualityScheme(GualitySchemeDeleteCommmand command)
        {
            Apiresult<int> apiresult = new Apiresult<int>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        /// <summary>
        /// 获取质检方案信息
        /// </summary>
        /// <param name="command">质检方案id</param>
        /// <returns>返回质检方案</returns>
        [HttpGet]
        public async Task<Apiresult<GualitySchemeDTO>> ModelGualityScheme([FromQuery]GualitySchemeModelCommmand command)
        {
            Apiresult<GualitySchemeDTO> apiresult = new Apiresult<GualitySchemeDTO>();
            try
            {
                apiresult.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                apiresult.Code = -1;
                apiresult.Message = ex.Message;
                throw;
            }
            return apiresult;
        }
        ///// <summary>
        ///// 获取特殊质检方案信息
        ///// </summary>
        ///// <param name="command">质检方案id</param>
        ///// <returns>返回质检方案</returns>
        //[HttpGet]
        //public async Task<Apiresult<List<GualityProject>>> SpecialModelGualityScheme()
        //{
        //    Apiresult<List<GualityProject>> apiresult = new Apiresult<List<GualityProject>>();
        //    try
        //    {
        //        apiresult.Data = await mediator.Send(new GualitySchemeSpecialModelCommmand());
        //    }
        //    catch (Exception ex)
        //    {
        //        apiresult.Code = -1;
        //        apiresult.Message = ex.Message;
        //        throw;
        //    }
        //    return apiresult;
        //}
    }
}
